<!DOCTYPE html>
<html lang="en-US">
  <head>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
  </head>
  <body>
    <main id="webchat"></main>
    <script>
      run(async function () {
        const directLine = testHelpers.createDirectLineWithTranscript();

        WebChat.renderWebChat(
          {
            directLine,
            store: testHelpers.createStore()
          },
          document.getElementById('webchat')
        );

        await pageConditions.uiConnected();

        const liveRegionElement = pageElements.liveRegion();

        // WHEN: A typing activity is sent by a participant with a name.
        //       Currently, Web Chat only support "bot" role for other participants.
        directLine.activityDeferredObservable.next({
          channelId: 'directline',
          from: {
            id: 'u00001',
            name: 'John',
            role: 'bot'
          },
          id: 'a00001',
          timestamp: new Date().toISOString(),
          type: 'typing'
        });

        // THEN: It should read "John is typing."
        await pageConditions.became(
          'typing indicator to appear in live region',
          async () => liveRegionElement.innerText === 'connecting\nJohn is typing.',
          5000
        );
      });
    </script>
  </body>
</html>
